<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商业伙伴编码" prop="bpCode" label-width="120px">
        <el-input v-model="queryParams.bpCode" placeholder="请输入商业伙伴编码" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="商业伙伴名称" prop="bpName" label-width="120px">
        <el-input v-model="queryParams.bpName" placeholder="请输入商业伙伴名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="启用标志" prop="enabledFlag">
        <el-select v-model="queryParams.enabledFlag" placeholder="请选择启用标志" clearable>
          <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini"
                   @click="handleAdd" v-hasPermi="['lease:bpMaster:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                   @click="handleUpdate" v-hasPermi="['lease:bpMaster:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                   @click="handleDelete" v-hasPermi="['lease:bpMaster:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" v-hasPermi="['lease:bpMaster:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bpMasterList" @selection-change="handleSelectionChange" border height="calc(100vh - 300px)">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="商业伙伴编码" align="center" prop="bpCode" width="150px">
        <template slot-scope="scope">
          <router-link :to="{path:'/lease/bpMaster/detail',query:{bpId: scope.row.bpId}}" class="link-type">
            <span>{{ scope.row.bpCode }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="商业伙伴名称" align="center" prop="bpName" width="250px" :show-overflow-tooltip="true"/>
      <el-table-column label="分类" align="center" prop="bpClass">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fnd_bp_class" :value="scope.row.bpClass"/>
        </template>
      </el-table-column>
      <el-table-column label="商业伙伴类别" align="center" prop="bpCategoryN" :show-overflow-tooltip="true"/>
      <el-table-column label="商业伙伴类型" align="center" prop="bpTypeN" :show-overflow-tooltip="true"/>
      <el-table-column label="单据所有者ID" align="center" prop="ownerUserId"/>
      <el-table-column label="启用标志" align="center" prop="enabledFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enabledFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['lease:bpMaster:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
                     @click="handleDelete(scope.row)" v-hasPermi="['lease:bpMaster:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {listBpMaster, getBpMaster, delBpMaster, addBpMaster, updateBpMaster} from "@/api/lease/bpMaster";

export default {
  name: "BpMaster",
  dicts: ['sys_yes_no','fnd_bp_class'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商业伙伴信息表格数据
      bpMasterList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ownerUserId: null,
        bpCode: null,
        bpName: null,
        extraNam: null,
        bpClass: null,
        bpCategory: null,
        bpType: null,
        enabledFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bpCode: [
          {required: true, message: "商业伙伴编码不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商业伙伴信息列表 */
    getList() {
      this.loading = true;
      listBpMaster(this.queryParams).then(response => {
        this.bpMasterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bpId: null,
        ownerUserId: null,
        bpCode: null,
        bpName: null,
        extraNam: null,
        bpClass: null,
        bpCategory: null,
        bpType: null,
        bpTitle: null,
        searchTerm1: null,
        searchTerm2: null,
        externalBpCode: null,
        addressId: null,
        enabledFlag: "0",
        firstName: null,
        middleName: null,
        lastName: null,
        gender: null,
        nationality: null,
        dateOfBirth: null,
        placeOfBirth: null,
        nameAtBirth: null,
        maritalStatus: "0",
        numberOfChildren: null,
        academicBackground: null,
        age: null,
        idType: null,
        idCardNo: null,
        annualIncome: null,
        currency: null,
        capitalOfFamily: null,
        liabilityOfFamily: null,
        legalForm: null,
        industry: null,
        businessLicenseNum: null,
        corporateCode: null,
        organizationCode: null,
        taxRegistryNum: null,
        registeredPlace: null,
        foundedDate: null,
        registeredCapital: null,
        balanceSheetCurrency: null,
        taxpayerType: null,
        invoiceTitle: null,
        invoiceBpAddressPhoneNum: null,
        invoiceBpBankAccount: null,
        loanCardNum: null,
        paidUpCapital: null,
        companyNature: null,
        primaryBusiness: null,
        mainProducts: null,
        bpNameSp: null,
        genderSp: null,
        dateOfBirthSp: null,
        academicBackgroundSp: null,
        idTypeSp: null,
        idCardNoSp: null,
        countrySp: null,
        provinceSp: null,
        citySp: null,
        districtSp: null,
        addressSp: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        refV01: null,
        refV02: null,
        refV03: null,
        refV04: null,
        refV05: null,
        refV06: null,
        refV07: null,
        refV08: null,
        refV09: null,
        refV10: null,
        refV11: null,
        refV12: null,
        refV13: null,
        refV14: null,
        refV15: null,
        refN01: null,
        refN02: null,
        refN03: null,
        refN04: null,
        refN05: null,
        refN06: null,
        refN07: null,
        refN08: null,
        refN09: null,
        refN10: null,
        refD01: null,
        refD02: null,
        refD03: null,
        refD04: null,
        refD05: null,
        enterpriseScale: null,
        legalPerson: null,
        spousePhone: null,
        licenseTerms: null,
        porportionOfGuarantee: null,
        periodInJob: null,
        netMonthlyIncome: null,
        leaderFlag: null,
        mortgageFlag: null,
        localPersonFlag: null,
        highMentalFlag: null,
        hasHouseFlag: null,
        hasCarFlag: null,
        communityLeaderFlag: null,
        bankMatchFlag: null,
        housePropertyValue: null,
        houseLoanBalance: null,
        depositCertificate: null,
        creditCardLimit: null,
        addressOnId: null,
        addressOnResidentBooklit: null,
        livingAddress: null,
        workingPlace: null,
        workingDuration: null,
        workingAddress: null,
        operationYear: null,
        position: null,
        cellPhone: null,
        phoneExtra: null,
        phone: null,
        contactPerson: null,
        faxNumber: null,
        department: null,
        creditFlag: null,
        creditAmount: null,
        creditAlt: null,
        creditForbid: null,
        email: null,
        ncStatus: "0",
        cellPhone2: null,
        employeeAmount: null,
        billingStatus: "0",
        finNetCashInflow: null,
        finMonthlyPayment: null,
        finMonths: null,
        finLiquidityRatio: null,
        finLeverage: null,
        finData: null,
        finEvaluation: null,
        cddListId: null,
        pbNumber: null,
        repoNumber: null,
        finNote1: null,
        finNote: null,
        blackFlag: null,
        lockFlag: null,
        oldFlag: null,
        limitFrom: null,
        limitTo: null,
        lawBpFlag: null,
        finTurnover1: null,
        finTurnover: null,
        ifToZxFlag: null,
        zxLastUpdateDate: null,
        zxLastUpdatedBy: null,
        creditAmountUsedFix: null,
        creditAmountUsedCycle: null,
        creditAmountFrozenFix: null,
        creditAmountFrozenCycle: null,
        pollingTimes: null,
        saleType: null,
        assetType: null,
        area: null,
        listedCompanyFlag: null,
        marketLocation: null,
        creditRating: null,
        ratingDate: null,
        invoiceKind: null,
        licenseTermsIfLong: null,
        listedSubject: null,
        listedSubjectOrgCode: null,
        actualControllerIdType: null,
        actualControllerId: null,
        actualControllerOrgCode: null,
        bpNameSpClass: null,
        actualController: null,
        authorityRuleString: null,
        bankShortName: null,
        finOrgType: null,
        bankCode: null,
        enterpriseUnifiedCreditcode: null,
        startActiveDate: null,
        endActiveDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.bpId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商业伙伴信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bpId = row.bpId || this.ids
      getBpMaster(bpId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商业伙伴信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.bpId != null) {
            updateBpMaster(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBpMaster(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bpIds = row.bpId || this.ids;
      this.$modal.confirm('是否确认删除商业伙伴信息编号为"' + bpIds + '"的数据项？').then(function () {
        return delBpMaster(bpIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lease/bpMaster/export', {
        ...this.queryParams
      }, `bpMaster_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
